/*********** tuannh ****************
 function : tool base gis
 ***********************************/
/** **** Base layer ******* */
function changeLayerBase(obj) {
	var objLayerBase = obj;
	if (objLayerBase.checked) {
		var layerBase = null;
		switch (objLayerBase.value) {
		case "OSM":
			layerBase = new OpenLayers.Layer.OSM("OSM", {
				numZoomLevels : 20
			});
			break;
		case "GSM":
			layerBase = new OpenLayers.Layer.Google("Google Streets", {
				numZoomLevels : 20
			});
			break;
		case "GSL":
			layerBase = new OpenLayers.Layer.Google("Google Satellite", {
				type : google.maps.MapTypeId.SATELLITE,
				numZoomLevels : 20
			});
			break;
		default:
			break;
		}
		if (layerBase != null)
		{
			map.addLayer(layerBase);
			map.setLayerIndex(layerBase, 1);
			map.removeLayer(map.layers[0]);
			// render OV
			map.removeControl(ctrl_OV);
			removeChild_Div(_divOV);
			ctrl_OV = new OpenLayers.Control.OverviewMap({
				"div" : OpenLayers.Util.getElement('OV')
			});
			map.addControl(ctrl_OV);
		}
	}
	return false;
	/*var ghyb = new OpenLayers.Layer.Google("Google Hybrid", {
		type : google.maps.MapTypeId.HYBRID,
		numZoomLevels : 20
	});*/
}

/** **** Measure ***** */
function event_Measure(evt) {
	if (!evt.checked) {
		for ( var key in measureControls) {
			control = measureControls[key];
			control.deactivate();
		}
		switch (evt.value) {
		case 'point':
			var control = measureControls["point"];
			control.activate();
			break;
		case 'line':
			var control = measureControls["line"];
			control.activate();
			break;
		case 'area':
			var control = measureControls["polygon"];
			control.activate();
			break;
		default:
			break;
		}
	}
}

function handleMeasurements(event) {
	var geometry = event.geometry;
	var units = event.units;
	var order = event.order;
	var measure = event.measure;
	var element = document.getElementById('span_Map_Measure_Detail');
	var out = "";
	// polyline
	if (order == 1) {
		out += "Độ dài: " + measure.toFixed(3) + " " + units;
	} else {
		// polygon && point
		if (geometry == undefined)
			out += "Diện tích: " + measure.toFixed(3) + " " + units
					+ "<sup>2</" + "sup>";
		else {
			var id = geometry.id.toLowerCase();
			if (id.indexOf("point") != -1) {
				out += "Tọa độ x = " + roundNumber(geometry.x, 2) + ", y = "
						+ roundNumber(geometry.y, 2);
			} else
				out += "Diện tích: " + measure.toFixed(3) + " " + units
						+ "<sup>2</" + "sup>";
		}
	}
	element.innerHTML = out;
}

function Measure_Close() {
	for ( var key in measureControls) {
		control = measureControls[key];
		control.deactivate();
	}
	getAttr("_div_Map_Measure", "display:none;");
	Portlet_Panel.setCurrent_ImgAction(panelPortlet,
			panelPortlet.current_ImgAction_Deault);
	return false;
}
/** ****** end function tool base gis ********* */
